//
//  KVFeatureCell.swift
//  KVBestMicroblog
//
//  Created by 李康卫 on 16/7/22.
//  Copyright © 2016年 李康卫. All rights reserved.
//

import UIKit

class KVFeatureCell: UICollectionViewCell {
    ///beginDidClick开始体验
    var beginTryBlock:(() -> Void)?
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //初始化UI
    override init(frame: CGRect) {
        super.init(frame: frame)
        //添加背景图
        setupUI()
    }
    // MARK: - 点击事件
    @objc private func beginDidClick() {
        beginTryBlock?()
    }
    //shareDidClick
    @objc private func shareDidClick(shareBtn: UIButton) {
        print("shareDidClick")
        shareBtn.selected = !shareBtn.selected
    }

    // MARK: - 私有方法
    ///是否隐藏btn
    func showBtns(isShow: Bool) {
        beginBtn.hidden = isShow
        shareBtn.hidden = isShow
    }

    private func setupUI() {
        self.contentView.addSubview(backgroundImg)
        self.contentView.addSubview(beginBtn)
        self.contentView.addSubview(shareBtn)
        
        //设置约束
        self.backgroundImg.snp_makeConstraints { (make) -> Void in
            make.edges.equalTo(self.contentView)
        }
        //设置按钮的约束
        self.beginBtn.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(self.contentView).offset(-160)
            make.centerX.equalTo(self.contentView)
        }
        
        self.shareBtn.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(self.beginBtn.snp_top).offset(-16)
            make.centerX.equalTo(self.contentView)
        }
    }
    
    //加载背景图
    lazy var backgroundImg: UIImageView = UIImageView(image: UIImage(named: "new_feature_1"))
    //创建Button
    lazy var beginBtn: UIButton = {
       let bnt = UIButton()
        bnt.setTitle("开始体验", forState: UIControlState.Normal)
        bnt.setBackgroundImage(UIImage(named: "new_feature_finish_button"), forState: UIControlState.Normal)
        //添加点击事件
        bnt.addTarget(self, action: "beginDidClick", forControlEvents: UIControlEvents.TouchUpInside)
        return bnt
    }()
    //创建Button
    lazy var shareBtn: UIButton = {
        let shareBtn = UIButton()
        shareBtn.setTitle("分享给好友", forState: UIControlState.Normal)
        shareBtn.setImage(UIImage(named: "new_feature_share_false"), forState: UIControlState.Normal)
//        bnt.setImage(UIImage(named:"new_feature_share_true", forState: UIControlState.Selected)
        shareBtn.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        shareBtn.setImage(UIImage(named: "new_feature_share_true"), forState: UIControlState.Selected)
        //添加点击事件
        shareBtn.addTarget(self, action: "shareDidClick:", forControlEvents: UIControlEvents.TouchUpInside)
        return shareBtn
    }()
}
